/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Kranthi
 */
package PHS;
import java.sql.*;
import java.util.*;
//import java.io.*;
public class BillDetails
{
    String url="jdbc:db2://localhost:50000/PHSYSTEM";
    String driver="com.ibm.db2.jcc.DB2Driver";
    String user="db2admin";
    String pwd="db2admin";
    ResultSet rs;
    Statement stmt;
    PreparedStatement pstmt;
    Connection conn=null;
    String paymode;
    int advancePaid;
    int pid;
    String pname;
    ArrayList bdate= new ArrayList();
    ArrayList pmode=new ArrayList();
    ArrayList advpaid=new ArrayList();
    ArrayList claimedamount=new ArrayList();
    ArrayList bno=new ArrayList();
    ArrayList details=new ArrayList();
    ArrayList amt=new ArrayList();
    ArrayList claim=new ArrayList();
    public BillDetails()
    {
        try
        {
        Class.forName(driver);
        conn=DriverManager.getConnection(url,user,pwd);
        stmt=conn.createStatement();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    public void setPid(int pid)
    {
        this.pid=pid;
        System.out.println("setter method for patientID:"+this.pid);
    }
    public void setadvancePaid(int advancePaid)
    {
        this.advancePaid=advancePaid;
        System.out.println("setter method for Advance Paid:"+this.advancePaid);
    }
    public void setPaymode(String paymode)
    {
        this.paymode=paymode;
        System.out.println("setter method for Advance Paid:"+this.paymode);
    }
    public void setBillDetails()
    {
      String query="SELECT Details, Amount, BillDate, Claim FROM BillDetails WHERE PatientID="+pid;
      String query1="SELECT BillNO, BillDate, PaymentMode, AdvPaid, ClaimAmount FROM Bill WHERE PatientID="+pid;
      try
         {
            rs=stmt.executeQuery(query);
            while(rs.next())
            {
                details.add(rs.getString("Details"));
                amt.add(rs.getInt("Amount"));
                bdate.add(rs.getString("BillDate"));
                claim.add(rs.getString("Claim"));
            }
            rs=stmt.executeQuery(query1);
            while(rs.next())
            {
                bno.add(rs.getInt("BillNO"));
                bdate.add(rs.getString("BillDate"));
                pmode.add(rs.getString("PaymentMode"));
                advpaid.add(rs.getInt("AdvPaid"));
                claimedamount.add(rs.getInt("ClaimAmount"));
            }
         }
      catch(SQLException e)
      {
          e.printStackTrace();
      }
    }
    public String getPatientName()
    {
        try
        {
            rs=stmt.executeQuery("SELECT Pname FROM Patientpersonal WHERE PatientId="+pid);
            while(rs.next())
            {
                pname=rs.getString("pname");
                System.out.println("Patient name:"+pname);
            }
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        return  pname;
    }    
    public int UpdateAmount()
    {
        int rowCount=0;
        try
        {
            String insert="INSERT INTO Bill(BillNo,PatientID,BillDate,PaymentMode,AdvPaid,ClaimAmount)"+
                    "VALUES((SELECT MAX(BillNo)+1 FROM Bill),"+pid+",CURRENT DATE,'"+paymode+"',"+advancePaid+","+0+")";
            conn.setAutoCommit(false);
           /* pstmt=conn.prepareStatement(insert);
            pstmt.setInt(2, pid);
            pstmt.setString(4,paymode);
            pstmt.setInt(5,advancePaid);*/
            rowCount=stmt.executeUpdate(insert);
            conn.commit();
        }
        catch(SQLException e)
        {
            e.printStackTrace();  
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    return rowCount;
    }
    public ArrayList getDetails()
    {
        System.out.println(details);
        return details;
    }
    public ArrayList getBillDate()
    {
        return bdate;
    }
    public ArrayList getAmount()
    {
        return amt;
    }
    public ArrayList getClaim()
    {
        return claim;
    }
    public ArrayList getBillNo()
    {
        return bno;
    }
    public ArrayList getPaymentMode()
    {
        return pmode;
    }
    public ArrayList getAdvPaid()
    {
        return advpaid;
    }
    public ArrayList getClaimedAmount()
    {
        return claimedamount;
    }
}
